package com.plum.admin.modules.sys.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.plum.admin.common.annotation.Log;
import com.plum.admin.common.enums.LogType;
import com.plum.admin.common.util.R;
import com.plum.admin.modules.sys.entity.SysDictItem;
import com.plum.admin.modules.sys.service.ISysDictItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.plum.admin.base.BaseController;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 字典详情表 前端控制器
 * </p>
 *
 * @author 子丶沫
 * @since 2021-09-17
 */
@RestController
@RequestMapping("/sys/dict/item")
@Api(tags = "字典项管理")
public class SysDictItemController extends BaseController {
    @Autowired
    private ISysDictItemService dictItemService;

    @ApiOperation("查询字典项列表")
    @GetMapping
    @Log(type = LogType.OPERATION,title = "查询字典项列表")
    public R<Object> list(Integer page, Integer pageSize, SysDictItem dictItem){
        return R.ok(dictItemService.findItemList(new Page<>(page,pageSize),dictItem));
    }
    @DeleteMapping
    @ApiOperation("删除字典值")
    @Log(type = LogType.OPERATION,title = "删除字典值")
    public R<Object> deleteDictItem(String ids){
        List<String> idList = Arrays.stream(ids.split(",")).collect(Collectors.toList());
        return R.ok(dictItemService.removeByIds(idList));
    }
    @PostMapping
    @ApiOperation("添加字典值")
    @Log(type = LogType.OPERATION,title = "添加字典值")
    public R<Object> addDictItem(@RequestBody SysDictItem dictItem){
        return R.ok(dictItemService.save(dictItem));
    }
    @PutMapping
    @ApiOperation("修改字典值")
    @Log(type = LogType.OPERATION,title = "修改字典值")
    public R<Object> editDictItem(@RequestBody SysDictItem dictItem){
        return R.ok(dictItemService.updateById(dictItem));
    }
}
